def isMatch(s: str, p: str) -> bool:
    n, m = len(s), len(p)
    s, p = ' ' + s, ' ' + p
    dp = [[False] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = True
    for i in range(0, n+1):
        for j in range(1, m+1):
            # 将 a* 看做一个整体，枚举到a的状态，正是 a* 中 * 代表 0 个 字符的情况
            if j + 1 <= m and p[j + 1] == '*':
                continue
            if i and p[j] != '*':
                dp[i][j] = dp[i-1][j-1] and (s[i] == p[j] or p[j] == '.')
            elif p[j] == '*':
                dp[i][j] = dp[i][j-2] or i != 0 and dp[i-1][j] and (s[i] == p[j - 1] or p[j-1] == '.')
    return dp[n][m]


"aa"
"a*"
print(isMatch("aa", "a*"))
